/**
 * 方法一:超时
 */

class Solution {
    public void rotate(int[] nums, int k) {
        if (nums.length != 0) {
            k = k % nums.length;
        }
        int len = 0;
        while (k > 0) {
            int temp = nums[len];
            for (int i = len; i < nums.length + len; i++) {

                int ret = temp;
                temp = nums[(i + 1) % nums.length];
                nums[(i + 1) % nums.length] = ret;

            }
            len = (len + 1) % nums.length;
            k--;
        }
    }
}
/**
 * 方法二:官方题解,运用Java生态
 */

class Solution2 {
    public void rotate(int[] nums, int k) {
        int n = nums.length;
        int[] newArr = new int[n];
        for (int i = 0; i < n; ++i) {
            newArr[(i + k) % n] = nums[i];
        }
        System.arraycopy(newArr, 0, nums, 0, n);//这个方法是复制数组的,感觉直接让nums指向newArr的引用也行
    }
}